#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>

int main(int argc, char* argv[]){
	if(argc < 2){
		write(STDOUT_FILENO, "用法：./mini_echo <要写的话>\n",35);
		return 1;
	}

	int fd = open("output.txt", O_WRONLY | O_CREAT | O_TRUNC, 0644);
	if(fd == -1){
		perror("open failed");
		return 1;
	}

	for(int i = 1; i < argc; i++){
		write(fd, argv[i], strlen(argv[i]));
		if(i < argc - 1){
			write(fd, " ", 1);
		}
	}

	write(fd, "\n", 1); // 最后加换行
        close(fd);
        return 0;
}
